#include<iostream>
#include<fstream>
#include<string>
#include<vector>
using namespace std;
ifstream fin;
ofstream fout;
//operation score;
const double cl=0.2;
const double pu=0.2;
const double pr=0.5;
const double ca=0.7;

//month score;
const double ap=0.2;
const double ma=0.2;
const double jn=0.25;
const double jl=0.3;
const double au=0.45;

const int mcrit=2;
const int ocrit=10;
string month[5]={"0"};
string mnum[5]={"0"};
static double sc=0;
struct node
{
    string a[4];
    int b;
};
bool getitem(node *c)
{
    if(!fin.eof())
    {
	for(int i=0;i<4;i++)
	    fin>>c->a[i];
	fin>>c->b;
	return 0;
    }
    return 1;
}
void wmonth(node *w)
{
    switch(w->a[3][0])
    {
	case '4':
	    month[0]="1";
	    break;
	case '5':
	    month[1]="1";
	    break;
	case '6':
	    month[2]="1";
	    break;
	case '7':
	    month[3]="1";
	    break;
	case '8':
	    month[4]="1";
	    break;
	default:
	    break;
    }
}
double mscore(string month[],node *tail)
{
    wmonth(tail);
    double op=0;
    switch(tail->a[2][0])
    {
	case '0':
	    op=cl;
	    break;
	case '1':
	    op=pu;
	    break;
	case '2':
	    op=pr;
	    break;
	case '3':
	    op=ca;
	    break;
    }
    if(month[0]=="1")
	sc+=ap*op*(tail->b);
    else if(month[1]=="1")
	sc+=ma*op*(tail->b);
    else if(month[2]=="1")
	sc+=jn*op*(tail->b);
    else if(month[3]=="1")
	sc+=jl*op*(tail->b);
    else if(month[4]=="1")
	sc+=au*op*(tail->b);
    for(int i=0;i<5;i++)
	month[i]="0";
    //cout<<sc<<endl;
}
void mnumber(string mnum[],node *tail)
{
    switch(tail->a[3][0])
    {
	case '4':
	    mnum[0]="1";
	    break;
	case '5':
	    mnum[1]="1";
	    break;
	case '6':
	    mnum[2]="1";
	    break;
	case '7':
	    mnum[3]="1";
	    break;
	case '8':
	    mnum[4]="1";
	    break;

    }
}

int main()
{
    fin.open("/home/pi/code/al/ubotsort.txt");
    fout.open("/home/pi/code/al/month_operate.txt",ios_base::app);
    node *tt=new node;
    getitem(tt);
    node *tail=tt;
    mnumber(mnum,tail);

    int num=0;
    while(true)
    {
	tt=new node;
	if(!getitem(tt))
	{
	    if(tt->a[0]==tail->a[0])
	    {
		if(tt->a[1]==tail->a[1])
		{
		    if(tt->a[2]==tail->a[2])
		    {
			if(tt->a[3][0]==tail->a[3][0])
			{
			    tail->b+=tt->b;
			    delete tt;
			    continue;
			}
			else
			{
			    mscore(month,tail);
			    mnumber(mnum,tail);
			    delete tail;
			    tail=tt;
			}
		    }
		    else
		    {
			mscore(month,tail);
			mnumber(mnum,tail);
			delete tail;
			tail=tt;
		    }
		}
		else
		{
		    mnumber(mnum,tail);
		    for(int i=0;i<5;i++)
			if(mnum[i]=="1")
			    num++;
		    for(int i=0;i<5;i++)
			mnum[i]="0";
		    mscore(month,tail);
		    fout<<tail->a[0]<<"\t"<<tail->a[1]<<"\t"<<sc<<"\t"<<num<<endl;
		    //cout<<++w<<endl;
		    delete tail;
		    tail=tt;
		    sc=0;
		    num=0;
		}
	    }
	    else
	    {
		mnumber(mnum,tail);
		for(int i=0;i<5;i++)
		    if(mnum[i]=="1")
			num++;
		for(int i=0;i<5;i++)
		    mnum[i]="0";
		mscore(month,tail);
		fout<<tail->a[0]<<"\t"<<tail->a[1]<<"\t"<<sc<<"\t"<<num<<endl;
		//cout<<++w<<endl;
		delete tail;
		tail=tt;
		sc=0;
		num=0;
	    }
	}
	else
	    break;
    }
    fout.close();
    fin.close();
}

